'''
for in 循环
'''

# 法一：
print('法一')
for row in range(1, 10):
    for col in range(1, row + 1):
        print('{} * {} = {:<4}'.format(row, col, row * col), end=' ')
    print()


# 法二：
print('法二')
for row in range(9, 0, -1):
    for col in range(1, row + 1):
        print('{} * {} = {:<4}'.format(row, col, row * col), end=' ')
    print()

# 法三：
print('法三')
for col in range(9, 0, -1):
    for row in range(9, 0, -1):
        if(col >= row):
            print('{} * {} = {:<4}'.format(row, col, row * col), end = ' ')
        else:
            print('{} {} {} {} {:<4}'.format(' ', ' ', ' ', ' ', ' '), end=' ')
    print()

# 法四：
print('法四')
for col in range(1, 10):
    for row in range(9, 0, -1):
            if(col >= row):
                print('{} * {} = {:<4}'.format(row, col, row * col), end = ' ')
            else:
                print('{} {} {} {} {:<4}'.format(' ', ' ', ' ', ' ', ' '), end=' ')
    print()

'''
while 循环
'''
# 法一
print('法一')
row = 1
col = 1
while row < 10:
    while col <= row:
        print('{} * {} = {:<4}'.format(row, col, row * col), end=' ')
        col = col + 1
    print()
    row = row + 1
    col = 1

# 法二
print('法二')
row = 9
col = 1
while row > 0:
    while col <= row:
        print('{} * {} = {:<4}'.format(row, col, row * col), end=' ')
        col = col + 1
    print()
    row = row - 1
    col = 1

# 法三
print('法三')
row = 9
col = 9
while col > 0:
    while row > 0:
        if col >= row:
            print('{} * {} = {:<4}'.format(row, col, row * col), end=' ')
        else:
            print('{} {} {} {} {:<4}'.format(' ', ' ', ' ', ' ', ' '), end=' ')
        row = row - 1
    print()
    row = 9
    col = col - 1

# 法四
row = 9
col = 1
while col < 10:
    while row > 0:
        if (col >= row):
            print('{} * {} = {:<4}'.format(row, col, row * col), end=' ')
        else:
            print('{} {} {} {} {:<4}'.format(' ', ' ', ' ', ' ', ' '), end=' ')
        row = row - 1
    print()
    row = 9
    col = col + 1

